package com.lagou.edu.service.impl;

import com.lagou.edu.anno.Transactional;
import com.lagou.edu.service.UserServiceAnno;
import com.lagou.edu.utils.ConnectionUtils;
import com.lagou.edu.utils.DruidUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author HZF
 * @date 2020/5/31 23:54
 * @description
 */
@Transactional
public class UserServiceAnnoImpl implements UserServiceAnno {
    @Override
    public void transfer(String fromNo, String toNo, int money) throws SQLException {
        Connection connection = ConnectionUtils.getConnection();
        String sql = "update account set money=? where cardNo=?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setInt(1,money - 100);
        preparedStatement.setString(2,fromNo);
        preparedStatement.execute();
        int i = 1/0;//主动抛出异常
        preparedStatement.setInt(1,money + 100);
        preparedStatement.setString(2,toNo);
        preparedStatement.execute();
    }
}
